#include "StdAfx.h"
#include "Database.h"

const std::string Database::ERROR_MESSAGE_TABLE_FILE_NAME = "Data/database/error_msg.csv";

Database::ERROR_MESSAGE_TABLE* Database::msErrorMsgTable = 0;

DWORD Database::VERSION = 20121204;

void Database::Initialize()
{
}

void Database::Finalize()
{
	SAFE_DELETE(msErrorMsgTable);
}

Database& Database::getSingleton()
{
	static Database s_database;
	return s_database;
}

bool Database::SaveAll()
{
	SaveErrorMessagesTable(0);

	return true;
}

void Database::SaveErrorMessagesTable(const char* filename)
{
	if (msErrorMsgTable)
		msErrorMsgTable->Save(filename);
}

bool Database::LoadErrorMessagesTable(const char* filename)
{
	SAFE_DELETE(msErrorMsgTable);
	msErrorMsgTable = new Database::ERROR_MESSAGE_TABLE;

	return msErrorMsgTable->Load(filename);
	
}

//---------------------------------------------------------------------------
Database::ERROR_MESSAGE_TABLE& Database::GetErrorMessageTable()
{
	if(!msErrorMsgTable)
	{
		msErrorMsgTable = new Database::ERROR_MESSAGE_TABLE;
		msErrorMsgTable->Load(ERROR_MESSAGE_TABLE_FILE_NAME.c_str());
	}
	return *msErrorMsgTable;
}